package com.equipment;

import com.util.EncodingUtil;

/**
 * 写系统信息
 * @author Administrator
 *
 */
public class WriteSysInfoRequest {
	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 数据长度
	private String code = "FD"; // 代码
	private String broadening = "C3"; // 扩展代码
	private String BCC = ""; // 异或校验值


	private String PsamDir = "DF01"; //PSAM目录  df01 2字节
	private String KeyType = "46"; //密钥类型 46 1字节
	private String SysInfo = ""; //写入的系统信息 99字节
	/**
	 * 拼接C3写系统信息
	 * @return
	 */
	public String getWriteSysInfo(String psamDir,String keyType,String sysInfo) {
		this.PsamDir = EncodingUtil.addzero(psamDir,2);
		this.KeyType = EncodingUtil.addzero(keyType, 1);
		this.SysInfo = EncodingUtil.addZeor(sysInfo,198);
		Length = EncodingUtil.desToHex((broadening+PsamDir+KeyType+SysInfo).length()/2,4);
		String DATA = RSCTL + Length + code + broadening + PsamDir + KeyType + SysInfo;
		BCC = EncodingUtil.yihuo(EncodingUtil.change(DATA));
		return  STX + DATA + BCC;
	}
}
